package com.aaa.controller.jl;

import com.aaa.pojo.jl.PlanSas;
import com.aaa.pojo.jl.ResltBean;
import com.aaa.service.jl.PlanSasService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;
import java.util.List;

@RestController
public class PlanSasController {
    @Autowired
    private PlanSasService planSasService;
    ResltBean resltBean = new ResltBean();
    @RequestMapping("/plSas")
    public ResltBean planSasFindAll(String page, String limit ){
        int count = planSasService.findCount();
        List<PlanSas> all1 = planSasService.findAll1(page, limit);
        resltBean.setCode(0);
        resltBean.setMsg("");
        resltBean.setCount(count);
        resltBean.setData(all1);
        return resltBean;

    }
    @RequestMapping("/plSasInsert")
    public ResltBean planSasInsert(PlanSas planSas){
        planSas.setTestCode((int) ((Math.random() * 9 + 1) * 100000));
        planSas.setCreateTime(new Date());
        int insert = planSasService.insert(planSas);
        resltBean.setCode(0);
        resltBean.setMsg("");
        resltBean.setCount(insert);
        resltBean.setData(planSas);
        return resltBean;
    }
    @RequestMapping("/planSasUpdate")
    public ResltBean planSasUpdate(PlanSas planSas){
       planSas.setUpdateTime(new Date());
        int update = planSasService.update(planSas);
        resltBean.setCode(0);
        resltBean.setMsg("");
        resltBean.setCount(update);
        resltBean.setData(planSas);
        return resltBean;
    }
    @RequestMapping("/planSasIdList")
    public  ResltBean planSasIdList(@RequestParam("idList") List idList){
        int i = planSasService.deleteList(idList);
        resltBean.setCode(0);
        resltBean.setMsg("");
        resltBean.setCount(i);
        resltBean.setData(idList);
        return resltBean;
    }
    @RequestMapping("/planSasDelete")
    public  ResltBean planSasId(String idList){
        System.out.println(idList);
        int delete = planSasService.delete(idList);
        resltBean.setCode(0);
        resltBean.setMsg("");
        resltBean.setCount(delete);
        resltBean.setData(idList);
        return resltBean;
    }
    @RequestMapping("/fuzzyPlanSas")
    public  ResltBean  fuzzyPlanSas(String testName ,String createBy,String page , String limit){
        int count = planSasService.queryCountLike(testName, createBy);
        List<PlanSas> planSas = planSasService.fuzzyPlanSas(testName, createBy,page,limit);
        resltBean.setCode(0);
        resltBean.setMsg("");
        resltBean.setCount(count);
        resltBean.setData(planSas);
        return resltBean;
    }
    @RequestMapping({"/toShowPlanSas.do"})
    public ModelAndView toShowPlanSas(ModelAndView modelAndView) {
        modelAndView.setViewName("showPlanSas");
        return modelAndView;
    }
}
